package cheqex.dao;

import org.apache.torque.util.Criteria;
import java.sql.Date;

import java.util.ArrayList;
import java.util.List;
/*
Withdrawals Peer:
addWithdrawals - adds withdrawals data
editWithdrawals - edit withdrawals data 
deleteWithdrawals -  delete withdrawals check data
*/

public class WithdrawalsPeer
    extends cheqex.dao.BaseWithdrawalsPeer
{
	public static boolean addWithdrawals(String checkNumber, int amt, String particulars, java.sql.Date checkDate, int id){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		criteria.add(WithdrawalsPeer.AMOUNT, amt);
		criteria.add(WithdrawalsPeer.PARTICULARS, particulars);
		criteria.add(WithdrawalsPeer.CHECKDATE, checkDate);
		criteria.add(WithdrawalsPeer.WEEKID, id);
		try{
			WithdrawalsPeer.doInsert(criteria);
			return true;
		}catch (Exception e) { 
			e.printStackTrace(); 
			return false;
		}
	}
	
	public static List<Withdrawals> retrieveAllWithdrawals(java.sql.Date date){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKDATE,date);
		
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<Withdrawals>();
		}
	}
	
	public static List<Withdrawals> retrieveWeekWithdrawals(int id){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.WEEKID,id);
		
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<Withdrawals>();
		}
	}
	
	public static boolean editWithdrawals(String checkNumber, int amt, String particulars, java.sql.Date date){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.AMOUNT, amt);
		criteria.add(WithdrawalsPeer.PARTICULARS, particulars);
		
		Criteria scriteria = new Criteria();
		scriteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		scriteria.add(WithdrawalsPeer.CHECKDATE, date);
		try{
			WithdrawalsPeer.doUpdate(scriteria, criteria);
			return true;
		}catch (Exception e) { 
			e.printStackTrace(); 
			return false;
		}
	}
	
	public static boolean deleteWithdrawals(String checkNumber, java.sql.Date date){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		criteria.add(WithdrawalsPeer.CHECKDATE, date);
		try{
			WithdrawalsPeer.doDelete(criteria);
			return true;
		}catch (Exception e){
			e.printStackTrace();
			return false;
		}
	}
	
	public static Withdrawals getCheck(String checkNumber, java.sql.Date date){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		criteria.add(WithdrawalsPeer.CHECKDATE, date);
		
		try{
			if((Withdrawals)WithdrawalsPeer.doSelect(criteria).get(0)!=null)
				return (Withdrawals)WithdrawalsPeer.doSelect(criteria).get(0);
			else return null;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Withdrawals> getData(String number){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, number);
		
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public static List<Withdrawals> filterWithdrawalsByCheckNo(String checkNumber){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<Withdrawals>();
		}
	}
	
	public static List<Withdrawals> filterWithdrawalsByCheckDate(java.sql.Date checkDate){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKDATE, checkDate);
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<Withdrawals>();
		}
	}
	public static List<Withdrawals> searchWithdrawalsParticular(String checkNumber, java.sql.Date checkDate){
		Criteria criteria = new Criteria();
		criteria.add(WithdrawalsPeer.CHECKNUMBER, checkNumber);
		criteria.add(WithdrawalsPeer.CHECKDATE, checkDate);
		try{
			return (List<Withdrawals>)WithdrawalsPeer.doSelect(criteria);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList<Withdrawals>();
		}
	}

}
